<meta charset="UTF-8">
<style type="text/css">
	.layui-form{
		margin-top: 0px;
	}
</style>
<div class="mcy_body">
	<div id="home">
		<ul class="breadcrumb">
			<li><span class="glyphicon glyphicon-home"></span>&emsp;当前位置：</li>
			<li class="active">博客审核</li>
		</ul>
		<table class="layui-hide" id = "blog_table" lay-filter="blog_table"></table>
		<script type="text/html" id="barDemo">
  			<a class="layui-btn layui-btn-xs" lay-event="visit"><i class="layui-icon">&#xe609;</i>访问</a>
  			<a class="layui-btn layui-btn-xs" lay-event="consent"><i class="layui-icon">&#xe6b2;</i>同意</a>
  			<a class="layui-btn layui-btn-xs" lay-event="refuse"><i class="layui-icon">&#x1007;</i>拒绝</a>
		</script>
	</div>
	
	<div id="blog_jy" style="display: none;">
		<span style="margin: 10px; font-size: 16px;">建议：</span><textarea id='jy' placeholder='请输入建议' class='layui-textarea'></textarea>
	</div>
</div>

<script>
layui.use("table", function(){
	var table = layui.table;
	table.render({
		elem: '#blog_table',
		url: 'blog/page2',
		title: '博客审核',
		height: 'full-230',
		page: true,
		cols: [ [
			{type:'radio', fixed: 'left'},
			{field: 'updateDate', title: '发布时间'},
			{field: 'title', title: '标题'},
			{field: 'textType', title: '博客类型'},
			{fixed: 'right', title:'操作', toolbar: '#barDemo'}
		] ]
	});
	
	table.on('tool(blog_table)', function(obj){
		var id = obj.data.id;
		if(obj.event === 'visit'){
			window.open("blog/visit?id="+id);
		}
		if(obj.event === 'consent'){
			$.post("blog/consent?id="+id, function(data){
				layui.use('layer', function(){
					var layer = layui.layer;
					if(data.success){
						layer.msg("操作成功！",{offset:'rb'});
						table.reload('blog_table',{
							url:'blog/page2'
						});
					}else{
						layer.msg("操作失败！",{offset:'rb'});
					}
				})
			})
		}
		if(obj.event === 'refuse'){
			layui.use('layer', function(){
				var layer = layui.layer;
				layer.open({
					type: 1,
					title: "博客审核",
					shade: 0.3,
					area: ['300px', '240px'],
					content: $("#blog_jy"),
					btn: ['确定', '取消'],
					yes: function(index, layero){
					    var jy = $("#jy").val();
					    $.post("blog/refuse?id="+id+"&jy="+jy, function(data){
					    	layui.use('layer', function(){
								var layer = layui.layer;
								if(data.success){
									layer.close(layer.index);
									layer.msg("操作成功！",{offset:'rb'});
									table.reload('blog_table',{
										url:'blog/page2'
									});
								}else{
									layer.msg("操作失败！",{offset:'rb'});
								}
							})
						})
					}
				});				
			})
			
			/* $.post("blog/refuse?id="+id, function(data){
				if(data.success){
					bootbox.alert("操作成功");
					table.reload('blog_table',{
						url:'blog/page2'
					});
				}else{
					bootbox.alert("操作成功");
				}
			}) */
		}
	});
});
</script>

